package com.strive.common.feign.fallback;

import com.strive.common.feign.UserService;
import com.strive.common.model.LoginAppUser;
import com.strive.common.model.base.Result;
import com.strive.common.model.dto.SysUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;

/**
 * @description:
 * @author: bingcun.chen
 * @Date: 2022/2/22 15:23
 * @Version 1.0
 */
@Slf4j
public class UserServiceFallbackFactory implements FallbackFactory<UserService> {
    @Override
    public UserService create(Throwable throwable) {
        return new UserService() {
            @Override
            public Result<SysUser> selectByUsername(String username) {
                log.error("通过用户名查询用户异常:{}", username, throwable);
                return Result.succeed(new SysUser());
            }

            @Override
            public Result<LoginAppUser> findByUsername(String username) {
                log.error("通过用户名查询用户异常:{}", username, throwable);
                return Result.succeed(new LoginAppUser());
            }

            @Override
            public Result<LoginAppUser> findByMobile(String mobile) {
                log.error("通过手机号查询用户异常:{}", mobile, throwable);
                return Result.succeed(new LoginAppUser());
            }

            @Override
            public Result<LoginAppUser> findByOpenId(String openId) {
                log.error("通过openId查询用户异常:{}", openId, throwable);
                return Result.succeed(new LoginAppUser());
            }
        };
    }
}
